@layout("home.main")
@section('content')
<div class="main-wrap">
    <div class="main">
        <div class="main-content">
        <div class="title">
                <div class="float-left fs14">
                    <a href="/">Turui</a> &raquo; {{ $archive->categorie->title }} ({{ $archive->categorie->archive()->count() }})
                </div>
            </div>
            <div class="main-box">
                <div class="topic-title">
                    <div class="topic-title-main float-left">
                        <h1>{{ $archive->title }}</h1>
                        <div class="topic-title-date">
                        By {{ $archive->user->uname }} at {{ Helper::gettime($archive->created_at) }} • {{ $archive->view }} 次点击        
                        </div>
                    </div>
                    <div class="detail-avatar">
                        {{ HTML::image($archive->user->userinfo->avatar,$archive->user->uname) }}
                    </div>
                </div>
                <div class="topic-content">
                    <p>{{ $archive->body }}</p>
       
                    <p class="tag">
                        @foreach (Helper::tags($archive->tag->keywords) as $tag)
                            {{ HTML::link("",$tag) }}
                        @endforeach
                    </p>
                    <div class="has_adv">
                    <h3>相关帖子：</h3>
                        <ul class="rel_list">
                            @foreach ($archive->like($archive->tag->keywords) as $tag)
                                 <li>{{ HTML::link('/archive/' . $tag->id,$tag->title) }}</li>
                            @endforeach
                        </ul>
                    </div>
                </div>
            </div>
            <!-- post main content end -->
            <script type="text/javascript">
                function replyto(somebd){
                    var con = document.getElementById("new-comment").value;
                    document.getElementsByTagName('textarea')[0].focus();
                    document.getElementById("new-comment").value = " @"+somebd+" " + con;
                }
            </script>
            @if ($comments)
            <div class="title">
            {{ count($comments) }} 回复  |  直到 {{ Helper::gettime($archive->updated_at) }}
            </div>
            <div class="main-box home-box-list">
                @foreach ($comments as $comment)
                <div class="commont-item">
                    <div class="commont-avatar">{{ HTML::image($comment->user->userinfo->avatar,"") }}</div>
                    <div class="commont-data">
                        <div class="commont-content">
                            <p>{{ $comment->body }}</p>
                        </div>

                        <div class="commont-data-date">
                            <div class="float-left">{{ $comment->user->uname }} at {{ Helper::gettime($comment->posttime) }}</div>
                            <div class="float-right">   
                                {{ HTML::link("","编辑") }}
                                 « 
                                {{ HTML::link("#new-comment","回复",array("onclick"=>"replyto('{$comment->user->uname}');")) }}
                                <span class="commonet-count">{{ !isset($i)?$i=1:++$i }} 楼</span>
                            </div>
                        </div>
                    </div>
                </div>
                @endforeach
            </div>
            @else
            <div class="no-comment">暂无发表过评论</div>
            @endif
            <!-- comment list end -->
            @if (Auth::check())
            <div class="title">
                <div class="float-left">添加一条新回复</div>
                <div class="float-right"><a href="#">↑ 回到顶部</a></div>
            </div>
            <div class="main-box"> 
                {{ Form::open("comment") }}
                {{ Form::token() }}
                {{ Form::hidden("archive_id",$archive->id) }}
                <p>{{ Form::textarea("content",null,array("id"=>"new-comment","class"=>"comment-text mll")) }}</p>
                <div class="float-right grey fs12">可直接粘贴图片地址</div>
                <div class="float-left"><input type="submit" value=" 提 交 " name="submit" class="textbtn"></div>
                    <div class="float-right fs12 grey">• 请尽量让自己的回复能够对别人有帮助，不欢迎无主题灌水，发现无内容测试、灌水一律禁言！</div>
                {{ Form::close() }}
            </div>
            
            <div class="title">
                <div class="float-left">上传图片</div>
            </div>
            <div class="main-box"> 
                {{ Form::button("上传",array("class"=>"button","id"=>"buttonUpload","onclick"=>"return ajaxFileUpload();")) }}
                {{ Form::file("imgfile",array("id"=>"imgfile","size"=>45,"class"=>"input")) }}
            </div>
            @else
            <div class="no-comment">请 <a href="/login" rel="nofollow">登录</a> 后发表评论</div>
            @endif

    </div>
    <!-- main-content end -->
        <div class="main-sider">
          @include("home.slidebar")
        </div>
        <!-- main-sider end -->
    </div>
    <!-- main end -->
</div>
@endsection